package com.andy.beef.ui.main.adapter


import androidx.core.content.ContextCompat
import com.andy.beef.R
import com.andy.beef.ui.main.bean.FenceBean
import com.blankj.utilcode.util.NumberUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder


/**
 *作者:luofan
 *创建时间:2021/3/24 14:28
 *描述:选择围栏
 */
class FenceChooseAdapter : BaseQuickAdapter<FenceBean, BaseViewHolder>(R.layout.item_cattle_fen_choose_layout) {

    var chooseFenBean: FenceBean? = null

    fun setSelectSource(fenBean: FenceBean?) {
        chooseFenBean = fenBean
        notifyDataSetChanged()
    }

    override fun convert(helper: BaseViewHolder, infoBean: FenceBean) {
        helper.setText(R.id.tv_name, "围栏名称:${infoBean.fenceName}")
        helper.setText(R.id.tv_number, "${infoBean.cattleNum}头")
        helper.setText(R.id.tv_barn, "牛舍:${infoBean.cowshedName}")
        val areaStr = NumberUtils.format(infoBean.area, 2)
        helper.setText(R.id.tv_area, "面积:${areaStr}")
        if (chooseFenBean != null && chooseFenBean!!.fenceId == infoBean.fenceId) {
            helper.setImageDrawable(R.id.iv_select, ContextCompat.getDrawable(context, R.mipmap.ic_select))
        } else {
            helper.setImageDrawable(R.id.iv_select, ContextCompat.getDrawable(context, R.mipmap.ic_unselect))
        }
    }
}